package notepad;

import java.awt.event.*;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;

import javax.swing.JFileChooser;

public class FileSaveOther implements ActionListener{

	public void actionPerformed(ActionEvent e) {
		JFileChooser chooser=new JFileChooser();
        int state=chooser.showSaveDialog(null);
        File file=chooser.getSelectedFile();
        if(state==JFileChooser.APPROVE_OPTION){
          try{  
        	  File dir = chooser.getCurrentDirectory();
	      	  	String name = chooser.getSelectedFile().getName();
	      	  	File file1 = new File(dir,name);
	      	  	Main.title=name;
	      	  	Main.f = file1;
	      	  	Main.note1.setTitle(name);
        	  	String content=ShowGUI.getText();
                StringReader read=new StringReader(content);
                BufferedReader in= new BufferedReader(read);
                FileWriter outOne=new FileWriter(file);
                BufferedWriter out= new BufferedWriter(outOne);
                String str=null;
                while((str=in.readLine())!=null){
                   out.write(str);
                   out.newLine();
                }
               in.close();
               out.close();
          } 
          catch(IOException e1){}
        }
		
	}
	
}